package com.heima.wemedia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.SensitiveSelectDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.mapper.WmSensitiveMapper;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WmSensitiveServiceImpl extends ServiceImpl<WmSensitiveMapper, WmSensitive> implements WmSensitiveService {


    @Override
    public ResponseResult selectAll(SensitiveSelectDto dto) {

        Page page = new Page(dto.getPage(), dto.getSize());
        LambdaQueryWrapper<WmSensitive> queryWrapper = new LambdaQueryWrapper<>();

        if (dto.getName() != null) {
            queryWrapper.like(WmSensitive::getSensitives, "%" + dto.getName() + "%");
        }

        Page result = this.page(page, queryWrapper);

        long total = result.getTotal();
        List records = result.getRecords();

        ResponseResult responseResult = new PageResponseResult(dto.getPage().intValue(),dto.getSize().intValue(),(int)total);
        responseResult.setData(records);
        return responseResult;
    }
}
